import request from '@/utils/request'

//根据spuId获取的sku详细信息的类型
export interface SkuInfoItemType {
    id?: number,
    spuId?: number,
    price: number,
    skuName: string,
    skuDesc: string,
    weight: string,
    tmId?: number,
    category3Id?: number | null,
    skuDefaultImg: string,
    isSale: number,
    createTime: string,
    skuImageList: SkuImageListType | null,
    skuAttrValueList: SkuAttrValueListType | null,
    skuSaleAttrValueList: SkuSaleAttrValueListType | null
}



//根据spuId获取的sku列表类型
export type SkuInfoListType = SkuInfoItemType[]

//sku详细信息中sku图片列表skuImgList某一项的类型
export interface SkuImageItemType {
    id?: number,
    skuId?: number,
    imgName: string,
    imgUrl: string,
    spuImgId?: number,
    isDefault: string
}

//sku详情中 sku图片列表数据的类型
export type SkuImageListType = SkuImageItemType[]

//sku详情中 sku的属性值列表中某一项的类型
export interface SkuAttrValueItemType {
    id?: number,
    attrId?: number,
    valueId?: number,
    skuId?: number,
    attrName: string,
    valueName: string
}

//sku详情中 sku的属性值列表类型
export type SkuAttrValueListType = SkuAttrValueItemType[]

//sku详情中 sku所拥有的销售属性列表中某一项的值
export interface SkuSaleAttrValueItemType {
    id?: number,
    skuId?: number,
    spuId?: number,
    saleAttrValueId?: number,
    saleAttrId?: number,
    saleAttrName: string,
    saleAttrValueName: string
}


//sku详情中 sku所拥有的销售属性列表类型
export type SkuSaleAttrValueListType = SkuSaleAttrValueItemType[]


//sku的分页列表数据
export interface SkuPageListType {
    records: SkuInfoListType,
    total: number,
    size: number,
    current: number,
    searchCount: boolean,
    pages: number

}

//1.根据skuId下架某个商品
export const requestcancelSale = (skuId: number) => {
    return request.get<any, null>(`/admin/product/cancelSale/${skuId}`)
}

//2.根据skuId上架某个商品
export const requestOnSale = (skuId: number) => {
    return request.get<any, null>(`/admin/product/onSale/${skuId}`)
}

//3.根据skuId删除某个sku
export const requestDeleteSku = (skuId: number) => {
    return request.delete<any, null>(`/admin/product/deleteSku/${skuId}`)
}

//4.根据skuId获取它的sku列表
export const requestFindBySpuId = (spuId: number) => {
    return request.get<any, SkuInfoListType>(`/admin/product/findBySpuId/${spuId}`)
}

//5.根据skuId获取它的详细信息
export const requestFindById = (skuId: number) => {
    return request.get<any, SkuInfoItemType>(`/admin/product/getSkuById/${skuId}`)
}

//6.获取sku分页列表
export const requestSkuList = (page: number, limit: number) => {
    return request.get<any, SkuPageListType>(`/admin/product/list/${page}/${limit}`)
}

//7.新增sku
export const requestSaveSkuInfo = (skuInfo: SkuInfoItemType) => {
    return request.post<any, null>(`/admin/product/saveSkuInfo`, skuInfo)
}